package com.ruoyi.web.controller.carte;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.request.*;
import com.ruoyi.system.service.carte.job.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * carte服务器Controller
 * 
 * @author ruoyi
 * @date 2024-02-28
 */
@Api( tags = {"Job相关接口"})
@Controller
@RequestMapping("/system/job")
public class XxkJobController extends BaseController
{
    @Autowired
    private IJobExecute jobExecuteImpl;
    @Autowired
    private IJobStatus jobStatusImpl;

    @Autowired
    private IJobStart jobStartImpl;

    @Autowired
    private IJobStop jobStopImpl;

    @Autowired
    private IJobRun jobRunImpl;

    @Autowired
    private IJobRemove jobRemoveImpl;

    @Autowired
    private IJobImage jobImageImpl;

    @ApiOperation(value = "执行job")
    @PostMapping("/executeJob")
    @ResponseBody
    public AjaxResult executeJob(@RequestBody JobExecuteRequest jobRequest) throws Exception
    {
        String result = jobExecuteImpl.executeJob(jobRequest);
        if(StringUtils.isBlank(result)){
            result="成功";
        }
        return AjaxResult.success("成功",result);
    }
    @ApiOperation(value = "获取job状态")
    @PostMapping("/jobStatus")
    @ResponseBody
    public String jobStatus(@RequestBody JobStatusRequest jobRequest)
    {
        String result = jobStatusImpl.jobStatus(jobRequest);
        return result;
    }


    @ApiOperation(value = "停止Job")
    @PostMapping("/stopJob")
    @ResponseBody
    public String stopJob(@RequestBody JobStopRequest jobRequest)
    {
        String result = jobStopImpl.stopJob(jobRequest);
        return result;
    }

    @ApiOperation(value = "启动Job")
    @PostMapping("/startJob")
    @ResponseBody
    public String startJob(@RequestBody JobStartRequest jobRequest)
    {
        String result = jobStartImpl.startJob(jobRequest);
        return result;
    }

    @ApiOperation(value = "从企业存储库执行Job")
    @PostMapping("/runJob")
    @ResponseBody
    public String runJob(@RequestBody JobRunRequest jobRequest)
    {
        String result = jobRunImpl.runJob(jobRequest);
        return result;
    }

    @ApiOperation(value = "删除Job")
    @PostMapping("/removeJob")
    @ResponseBody
    public String removeJob(@RequestBody JobRemoveRequest jobRequest)
    {
        String result = jobRemoveImpl.removeJob(jobRequest);
        return result;
    }

    @ApiOperation(value = "获取job图片")
    @PostMapping("/jobImage")
    @ResponseBody
    public void jobImage(@RequestBody JobImageRequest jobRequest, HttpServletResponse response)
    {
        jobImageImpl.jobImage(jobRequest,response);
    }

}
